import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { ItemList } from '@components'
import jump from '@utils/jump'

import './index.scss'

export default class Module extends Component {
  static defaultProps = {
    list: []
  }

  handleClickModule = (module) => {
    if (module.linkUrl) {
      jump({
        url: module.linkUrl
      })
    }
  }

  render () {
    const { list } = this.props
    return (
      <View className='home-module'>
        {list.map((module) => (
          {
            2:
            <View className='home-module__act' key={module.id} onClick={this.handleClickModule.bind(this, module)}>
              <Image mode='widthFix' style={{ width: Taro.pxTransform(750) }} src={module.modulePic} />
            </View>,
            3:
              <View className='home-module__subject' key={module.id}>
                <Image mode='widthFix' style={{ width: Taro.pxTransform(750) }} src={module.modulePic}
                       onClick={this.handleClickModule.bind(this, module)} />
                <ItemList list={module.itemList} showTitle={false} columnNum={module.itemCol} >
                </ItemList>
              </View>
          }[module.moduleType]

        ))}
      </View>
    )
  }
}
